using System.Collections.Generic;
using System.Linq;
using System.Web.UI;
using Ext.Net;


namespace Ext.Net.UIS
{
    public class FieldUnionEditor : TermEditor
    {

        public static FieldUnionEditor Default = new FieldUnionEditor();

        public override bool MustMerge(TermNode parent)
        {
            return parent.IsUnion() && parent.Editor is FieldUnionEditor;
        }

        public override IEnumerable<AbstractComponent> NewControls(TermNode node, UisCreateControlArgs e)
        {
            var row = new FieldUnion { TermNode = node, ViewState = e.BaseViewState };

            e.BaseViewState = null;
            var list = node.NewItemControls(e).ToList();
            row.Items.AddRange(list);

            return new[] { row };
        }

    }
}